package com.hxzy.course.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.hxzy.course.pojo.Course;
import com.hxzy.course.pojo.Staff;
import com.hxzy.course.pojo.Time;
import com.hxzy.course.service.ArrangeCourseService;
import com.hxzy.course.service.CourseService;
import com.hxzy.course.service.StaffService;
import com.hxzy.course.service.TimeService;
import com.hxzy.region.pojo.ClassRoom;
import com.hxzy.region.pojo.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class CourseController {
    @Autowired
    private CourseService cs;
    @Autowired
    private StaffService ss;
    @Autowired
    private ArrangeCourseService arrangeCourseService;
    @Autowired
    private TimeService timeService;

    @RequestMapping("/getAllTeacher")
    @ResponseBody
    public List<Staff> getAllTeacher(){
        List<Staff> list = ss.getAllTeacher();
        return list;
    }

    @RequestMapping("/getTuanke")
    @ResponseBody
    public List<Course> getTuanke(){
        List<Course> list = cs.queryTuanKe();
        return list;
    }

    @RequestMapping("/getTeacher")
    @ResponseBody
    public List<Staff> getTeacher(){
        List<Staff> list = ss.getAllTeacher();
        return list;
    }

    @RequestMapping("/getTime")
    @ResponseBody
    public List<Time> getTime(){
        List<Time> list = timeService.getAllTime();
        return list;
    }

    @ResponseBody
    @RequestMapping("/getRegion")
    public List<Region> getRegion(){
        List<Region> list = cs.getAllRegion();
        return list;
    }

    @ResponseBody
    @RequestMapping("/getClassRoom")
    public List<ClassRoom> getClassRoom(String reId){
        List<ClassRoom> list = cs.queryClassRoom(reId);
        return list;
    }

    @RequestMapping("/addCourse")
    public String addCourse(Course course,String teacherId){
        cs.addCourse(course,teacherId);
        return "redirect:/view/pages/course/courseadd.html";
    }

    @PostMapping("/addPrivateCourse")
    @ResponseBody
    public boolean addPrivateCourse(String teacherId, String course){
        Gson g = new Gson();
        Course c = g.fromJson(course, Course.class);
        System.out.println(c);
        boolean a = cs.addCourse(c,teacherId);
        return a;
    }

    @RequestMapping("/getTuankeSchedule")
    @ResponseBody
    public Page<Map<String, Object>> getTukeSchedule(Integer pageNum,Integer pageSize){
        Page<Map<String, Object>> list = arrangeCourseService.getTuankeSchedule(pageNum,pageSize);
        return list;
    }

    @RequestMapping("/conditionQueryTuanke")
    @ResponseBody
    public Page<Map<String, Object>> conditionQueryTuanke(String time, String location,String space, String teacher, String course,String duringTime,Integer pageNum,Integer pageSize){
        Page<Map<String, Object>> list = cs.conditionQueryTuanke(time,location,space,teacher,course,duringTime,pageNum,pageSize);
        return list;
    }

    @RequestMapping("/conditionQuerySijiao")
    @ResponseBody
    public Page<Map<String, Object>> conditionQuerysijiao(String time, String location,String space, String teacher, String course,String duringTime,Integer pageNum,Integer pageSize){
        Page<Map<String, Object>> list = cs.conditionQuerySijiao(time,location,space,teacher,course,duringTime,pageNum,pageSize);
        return list;
    }

    @RequestMapping("/addArrangeCourse")
    @ResponseBody
    public boolean addArrangeCourse(String courseId,String timeId,String date,String qLocation,String qSpace){
        return arrangeCourseService.addArrangeCourse(courseId,timeId,date,qLocation,qSpace);
    }

    @ResponseBody
    @RequestMapping("/getCourseInfo")
    public Page<Map<String, Object>> getCourseInfo(Integer pageNum,Integer pageSize){
        Page<Map<String, Object>> list = cs.getCourseInfo(pageNum,pageSize);
        return list;
    }

    @ResponseBody
    @RequestMapping("/deleteSchedule")
    public boolean deleteSchedule(String delFlag,String delId){
        return arrangeCourseService.deleteSchedule(delFlag,delId);
    }

    @ResponseBody
    @RequestMapping("/deleteCourse")
    public boolean deleteCourse(String delFlag,String delId){
        return cs.deleteSchedule(delFlag,delId);
    }

    @ResponseBody
    @RequestMapping("/getOrderCourseInfo")
    public List<Map<String,Object>> getOrderCourseInfo(String co_name){
        List<Map<String, Object>> list = cs.getOrderCourseInfo(co_name);
        return list;
    }
}
